﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Drawing;

namespace QExcel
{
    public abstract class QItem
    {
        public QSheet Sheet
        {
            get;
            set;
        }

        /// <summary>
        /// 高
        /// </summary>
        public int Height
        {
            get;
            set;
        }

        XlBorderWeight borderWeight = XlBorderWeight.xlMedium;
        public XlBorderWeight BorderWeight
        {
            get
            {
                return borderWeight;
            }
            set
            {
                borderWeight = value;
            }
        }

        private XlHAlign xaLign = XlHAlign.xlHAlignCenter;
        public XlHAlign HorizonAlign
        {
            get
            {
                return xaLign;
            }
            set
            {
                xaLign = value;
            }
        }

        /// <summary>
        /// 背景色
        /// </summary>
        public Color BgColor
        {
            get;
            set;
        }

        /// <summary>
        /// 字体颜色
        /// </summary>
        public Color FontColor
        {
            get;
            set;
        }

        /// <summary>
        /// 是否粗体
        /// </summary>
        public bool IsBold
        {
            get;
            set;
        }

        private int fontSize = 12;
        /// <summary>
        /// 字体大小
        /// </summary>
        public int FontSize
        {
            get
            {
                return fontSize;
            }
            set
            {
                fontSize = value;
            }
        }

        public abstract void Output();


        /// <summary>
        /// 虚线：XlBorderWeight=xlHairline
        /// </summary>
        /// <param name="xAlign"></param>
        /// <param name="?"></param>
        public void SetStyle(Range range)
        {
            range.Select();
            range.HorizontalAlignment = xaLign;
            range.VerticalAlignment = XlHAlign.xlHAlignCenter;
            range.Borders.get_Item(XlBordersIndex.xlEdgeLeft).LineStyle = XlLineStyle.xlContinuous;
            range.Borders.get_Item(XlBordersIndex.xlEdgeRight).LineStyle = XlLineStyle.xlContinuous;
            range.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = XlLineStyle.xlContinuous;
            range.Borders.get_Item(XlBordersIndex.xlEdgeBottom).LineStyle = XlLineStyle.xlContinuous;
            try
            {
                range.Borders.get_Item(XlBordersIndex.xlInsideHorizontal).LineStyle = XlLineStyle.xlContinuous;
                range.Borders.get_Item(XlBordersIndex.xlInsideVertical).LineStyle = XlLineStyle.xlContinuous;
                range.Borders.get_Item(XlBordersIndex.xlInsideHorizontal).Weight = this.BorderWeight;
                range.Borders.get_Item(XlBordersIndex.xlInsideVertical).Weight = this.BorderWeight;
            }
            catch
            {
            }

            range.Font.Bold = this.IsBold;

            if (this.FontColor.ToArgb() != Color.FromArgb(0, 0, 0, 0).ToArgb())
            {
                range.Font.Color = ColorTranslator.ToOle(this.FontColor);// string.Format("{0},{1},{2}", this.FontColor.R, this.FontColor.B, this.FontColor.G);

            }
            if (this.BgColor.ToArgb() != Color.FromArgb(0, 0, 0, 0).ToArgb())
            {
                range.Interior.Color = ColorTranslator.ToOle(this.BgColor);
            }
            range.Font.Size = this.fontSize;
        }
    }
}
